package ui.common
{
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.events.MouseEvent;

	import globals.Global;

	/**
	 * 装备强化时的Item.
	 * @author luguobin
	 */
	public class EquipUpItem extends Sprite
	{
		private var _id:int;
		private var _clickCallback:Function;
		private var _selected:Boolean;
		private var _bg:Bitmap;

		public function EquipUpItem(id:int = 0, clickCallback:Function = null)
		{
			_id = id;
			_clickCallback = clickCallback;
			_bg = new Bitmap();
			_bg.bitmapData = Global.assetsManager.getAssetsAsBitmapData("uquip_levelUp_bg");
			this.addChild(_bg);
			this.addEventListener(MouseEvent.CLICK, clickHandler);
		}

		private function clickHandler(event:MouseEvent):void
		{
			selected = !_selected;

			if(_clickCallback != null)
			{
				_clickCallback(this);
			}
		}

		public function update():void
		{

		}

		public function get id():int
		{
			return _id;
		}

		public function set id(value:int):void
		{
			_id = value;
		}

		public function get selected():Boolean
		{
			return _selected;
		}

		public function set selected(value:Boolean):void
		{
			_selected = value;

			if(value)
			{
				_bg.bitmapData = Global.assetsManager.getAssetsAsBitmapData("uquip_levelUp_select");
			}
			else
			{
				_bg.bitmapData = Global.assetsManager.getAssetsAsBitmapData("uquip_levelUp_bg");
			}
		}

		public function get clickCallback():Function
		{
			return _clickCallback;
		}

		public function set clickCallback(value:Function):void
		{
			_clickCallback = value;
		}
	}
}